<template>
    <div class="person">
        <h2>姓名:{{ name }}</h2>
        <h2>年龄:{{ age }}</h2>
        <button @click="changeName">修改名字</button>
        <button @click="changeAge">修改年龄</button>
        <button @click="showTel">查看联系方式</button>
        <hr>
        <h2>测试:{{ a }}</h2>
        <h2>测试:{{ c }}</h2>
        <h2>测试:{{ d }}</h2>
        <button @click="b">test</button>
    </div>
</template>

<script lang="ts">
import { ref } from 'vue'

export default {
    name: "Person",
    beforeCreate() {
        console.log('beforeCreate')
    },
    //vue2 可以和vue3共存,vue2可以读取setup中的数据,vue3中不能读取vue2中的数据
    data() {
        return {
            a: 100,
            c: this.name,
            d:1200
        }
    },
    methods: {
        b() {
            console.log('b')
        }
    },

    setup() {

        //数据 原来是写在data中,此时nameage tel不是响应式
        let name = '张三'
        let age = 14
        let tel = '18823282323'

        // methods
        function changeAge() {
            age += 1
        }
        function changeName() {
            name = 'zhangsan'
        }
        function showTel() {
            alert(tel)
        }

        return { name, age, tel, changeAge, changeName, showTel }


        // return () => '哈哈'

    }
}
</script>

<style scoped>
.person {
    background-color: skyblue;
    box-shadow: 0 0 10px;
    border-radius: 10px;
    padding: 20px;
}

button {
    margin: 0 5px;
}
</style>
